#pragma once
#include "RBTree.h"
#include"reverse_iterator.h"

namespace zsw {
	template<class Key, class Value>
	class map
	{
		struct MAPofKEY
		{
			Key operator()(const pair<Key, Value>& date)
			{
				return date.first;
			}
		};
		typedef RBTree<Key, pair<const Key, Value>, MAPofKEY> _map;
	public:
		typedef typename RBTree<Key, pair<const Key, Value>, MAPofKEY>::iterator iterator;
		typedef typename RBTree<Key, pair<const Key, Value>, MAPofKEY>::const_iterator const_iterator;
		typedef typename RBTree<Key, pair<const Key, Value>, MAPofKEY>::reverse_iterator reverse_iterator;
		typedef typename RBTree<Key, pair<const Key, Value>, MAPofKEY>::reverse_const_iterator reverse_const_iterator;
		iterator begin()
		{
			return m.begin();
		}

		iterator end()
		{
			return m.end();
		}

		const_iterator begin() const
		{
			return m.begin();
		}

		const_iterator end() const
		{
			return m.end();
		}

		reverse_iterator rbegin()
		{
			return m.rbegin();
		}

		reverse_iterator rend()
		{
			return m.rend();
		}

		reverse_const_iterator rbegin() const
		{
			return m.rbegin();
		}

		reverse_const_iterator rend() const
		{
			return m.rend();
		}

		pair<iterator, bool> insert(const pair<Key, Value>& pa)
		{
			return m.Insert(pa);
		}

		Value& operator[](const Key& k)
		{
			pair<iterator, bool> ret = insert(make_pair(k, Value()));
			return (ret.first)->second;
		}

	private:
		_map m;
	};
}